package com.cheeven.cwliu.citation.steps;

import java.util.HashMap;
import org.w3c.dom.Document;

public class Step7 extends StepBase {

	public static void requestCSVFile(HashMap<String, String> control) {
		logInfo("7. Request CSV Files");

		String mark_from = control.get("mark_from");
		String mark_to = control.get("mark_to");
		String qid = control.get("qid");
		String sid = control.get("sid");

		logInfo(1, "sid={0}", control.get("sid"));
		logInfo(1, "qid={0}", control.get("qid"));
		logInfo(1, "hitCount={0}", control.get("hitCount"));
		
		String downloadTextPage = httpPost("http://apps.webofknowledge.com/OutboundService.do?action=go",
				new String[][]{
					{"viewType", "summary"},
					{"product", "WOS"},
					{"mark_id", "WOS"},
					{"colName", "WOS"},
					{"search_mode", "CitationReport"},
					{"locale", "en_US"},
					{"sortBy", "LC.D;PY.D;LD.D;SO.A.en;VL.D;PG.A;AU.A.en"},
					{"mode", "outputService"},
					{"qid", qid},
					{"SID", sid},
					{"format", "crsaveToFile"},
					{"filters", "DUMMY_VALUE"},
					{"selectedIds", ""},
					{"mark_to", mark_to},
					{"mark_from", mark_from},
					{"count_new_items_marked", "0"},
					{"mode", "quickOutput"},
					{"additional_qoutput_params", "cr_qid=" + qid},
					{"print_opt", "Html"},
					{"include_mark_from_in_url", "true"},
					{"redirect_url", ""},
					{"endYear", "2013"},
					{"startYear", "2009"},
					{"fields", "DUMMY_VALUE"},
					{"value(record_select_type)", "range"},
					{"markFrom", mark_from},
					{"markTo", mark_to},
					{"save_options", "tabWinUnicode"}});
		Document domdoc = toDOM(downloadTextPage);
		control.put("sid", xpath("//input[@name='SID']/@value", domdoc));
		control.put("qid", xpath("//input[@name='qid']/@value", domdoc));
		control.put("parentQid", xpath("//input[@name='parentQid']/@value", domdoc));
		control.put("numRecsToRetrieve", xpath("//input[@name='numRecsToRetrieve']/@value", domdoc));
		control.put("numRecords", xpath("//input[@name='numRecords']/@value", domdoc));
		control.put("recNum", xpath("//input[@name='recNum']/@value", domdoc));
		control.put("mark_to", xpath("//input[@name='mark_to']/@value", domdoc));
		control.put("returnUrl", xpath("//img[@alt='Return']/../@href", domdoc));

	}
}
